Page({
  data: {
    musics: [{
        "src": "http://kr.aynakedu.com/libs/files/audio1(1).mp3",
        "poster": "https://t7.baidu.com/it/u=3834250242,3564243367&fm=193&f=GIF",
        "name": "nahxa1",
        "author": "kadihan",
      },



      {
        "src": "http://kr.aynakedu.com/libs/files/audio1(2).mp3",
        "poster": "https://t7.baidu.com/it/u=610975408,2185098007&fm=193&f=GIF",
        "name": "nahxa2",
        "author": "sayimahun",
      },

      {
        "src": "http://kr.aynakedu.com/libs/files/audio1(3).mp3",
        "poster": "https://t7.baidu.com/it/u=1669459999,1595864521&fm=193&f=GIF",
        "name": "nahxa3",
        "author": "siyit",
      },

      {
        "src": "http://kr.aynakedu.com/libs/files/audio1(4).mp3",
        "poster": "https://t7.baidu.com/it/u=2654893497,1644642978&fm=193&f=GIF",
        "name": "nahxa4",
        "author": "yumurqi",
      },
    ],
    src: "",
    poster: "",
    name: "",
    author: "",
    state: "",

    percent: "0",
    musicScond: "0",
    musicMinute: "0",

    Second: "0",
    Minute: "0",


  },



  play: function (e) {
    let that = this;
    console.log(e);
    that.setData({
      src: e.currentTarget.dataset.src,
      poster: e.currentTarget.dataset.poster,
      name: e.currentTarget.dataset.name,
      author: e.currentTarget.dataset.author,
      state: e.currentTarget.dataset.state,
    });
    this.myAudio = wx.createAudioContext('myAudio');
    this.myAudio.play();
    this.setData({
      state: "play",
    })
  },

  pause: function (e) {
    console.log(e);

    let state = e.currentTarget.dataset.state;
    if (state == "play") {
      this.myAudio.pause()
      this.setData({
        state: "pause",
      })
    } else {
      this.myAudio.play()
      this.setData({
        state: "play",
      })
    }
  },

  musictimeupdate: function (e) {
    // console.log(e.detail);
    let that = this;
    let duration = parseInt(e.detail.duration - e.detail.currentTime);
    let percent = parseInt((e.detail.currentTime / e.detail.duration) * 100);


    let Second = parseInt(e.detail.duration);
    let Minute = parseInt(e.detail.duration);


    let slideMax = parseInt((e.detail.duration));
    let slideValue = parseInt((e.detail.currentTime));
    this.setData({
      musicScond: duration % 60, //音频的目前秒数
      musicMinute: parseInt(duration / 60), ////音频的目前分钟数


      Second: Second % 60, //音频的总时长（秒）
      Minute: parseInt(Minute / 60), //音频的总时长（分钟）


      percent: percent,
      slideMax: slideMax,
      slideValue: slideValue,
    })
  },

  surux: function (e) {
    console.log(e);
    this.myAudio.seek(e.detail.value);
  }
});